%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Diagrams-Communications.tex --- Example of communications diagram
%%
%% Author          : Denis GIROU (CNRS/IDRIS - France) <Denis.Girou@idris.fr>
%% Created the     : March 1996
%% Last mod. by    : hv
%% Last mod. the   : 2004-11-13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass{article}

\usepackage{pstricks}
\usepackage{pst-node}

\usepackage{multido}

% Definition of new colors
\definecolor{LightBlue}{rgb}{0.68,0.85,0.9}
\definecolor{PaleGreen}{rgb}{0.88,1,0.88}

\newcommand{\BackgroundColor}{PaleGreen}

\newcommand{\Process}{%
\pspolygon[linearc=0.8,fillstyle=solid,fillcolor=\BackgroundColor]%
          (0,-0.2)(-0.5,1.8)(0.2,3)(3,3.7)(7.5,3.2)(7.5,1.5)
          (6,-0.4)(2.5,-0.4)(1.5,0.3)
\begin{psmatrix}[rowsep=1cm,mnode=circle,fillstyle=solid,fillcolor=yellow]
            & [name=P0] 0 & [name=P1] 1                           \\[-6mm]
            &             & [name=P3,colsep=-1cm] 3               \\[-1.3cm]
[name=P2] 2 &             &                         & [name=P4] 4 \\[-2mm]
            &             & [name=P5,colsep=0cm]  5 & [name=P6,colsep=-0.8cm] 6
\end{psmatrix}

\psset{arrows=->,arcangle=30,arrowsize=4pt 2,labelsep=2pt}}

\pagestyle{empty}

\begin{document}

\begin{figure}[!h]
  \centering
  \Process
  \multido{\i=0+1}{7}{%
    \ifnum\i=3
      \nccircle[arrowsize=2pt 2]{P3}{3mm}
    \else
      \ncarc{P3}{P\i}
    \fi}
  \caption{Broadcast: \texttt{MPI\_BCAST}}
\end{figure}

\vspace{1cm}
\begin{figure}[!h]
  \centering
  \Process
  \multido{\i=0+1}{7}{%
    \ifnum\i=3
    \else
      \ncarc{P\i}{P3}
    \fi}
  \multido{\i=4+1}{3}{%
    \ncarc{P\i}{P3}}
  \caption{Reduction: \texttt{MPI\_REDUCE}}
\end{figure}

\vspace{1cm}
\begin{figure}[!h]
  \centering
  \Process
  \psset{arcangle=13}
  \multido{\i=0+1}{7}{%
    \ifnum\i=3
    \else
      \ncarc{P\i}{P3}
    \fi}
  \psset{linecolor=red}
  \multido{\i=0+1}{7}{%
    \ifnum\i=3
    \else
      \ncarc{P3}{P\i}
    \fi}
  \caption{\texttt{MPI\_ALLREDUCE}: reduction with broadcasting of the result}
\end{figure}

\end{document}
